home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / gnome-applets / invest-applet < prev    next >
Text File  |  2009-10-20  |  3KB  |  101 lines

  1. #!/usr/bin/env python
  2. #
  3.  
  4. import gobject
  5. import gtk, gnomeapplet
  6.  
  7. import getopt, sys
  8. from os.path import *
  9.  
  10. # Allow to use uninstalled
  11. def _check(path):
  12.     return exists(path) and isdir(path) and isfile(path+"/Makefile.am")
  13.  
  14. name = join(dirname(__file__), '..')
  15. if _check(name):
  16.     print 'Running uninstalled invest, modifying PYTHONPATH'
  17.     sys.path.insert(0, abspath(name))
  18. else:
  19.     sys.path.insert(0, abspath("/usr/lib/python2.6/dist-packages/"))
  20.  
  21. # Now the path is set, import our applet
  22. import invest, invest.applet, invest.defs
  23.  
  24. # Prepare i18n
  25. import gettext, locale
  26. gettext.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  27. gettext.textdomain(invest.defs.GETTEXT_PACKAGE)
  28. locale.bindtextdomain(invest.defs.GETTEXT_PACKAGE, invest.defs.GNOMELOCALEDIR)
  29. locale.textdomain(invest.defs.GETTEXT_PACKAGE)
  30.  
  31. from gettext import gettext as _
  32.  
  33. def applet_factory(applet, iid):
  34.     invest.debug('Starting invest instance: %s %s'% ( applet, iid ))
  35.     invest.applet.InvestApplet(applet)
  36.     return True
  37.  
  38. # Return a standalone window that holds the applet
  39. def build_window():
  40.     app = gtk.Window(gtk.WINDOW_TOPLEVEL)
  41.     app.set_title(_("Invest Applet"))
  42.     app.connect("destroy", gtk.main_quit)
  43.     app.set_property('resizable', False)
  44.  
  45.     applet = gnomeapplet.Applet()
  46.     applet_factory(applet, None)
  47.     applet.reparent(app)
  48.  
  49.     app.show_all()
  50.  
  51.     return app
  52.  
  53.  
  54. def usage():
  55.     print """=== Invest applet: Usage
  56. $ invest-applet [OPTIONS]
  57.  
  58. OPTIONS:
  59.     -h, --help            Print this help notice.
  60.     -d, --debug            Enable debug output (default=off).
  61.     -w, --window        Launch the applet in a standalone window for test purposes (default=no).
  62.     """
  63.     sys.exit()
  64.  
  65. if __name__ == "__main__":
  66.     standalone = False
  67.  
  68.     try:
  69.         opts, args = getopt.getopt(sys.argv[1:], "hdw", ["help", "debug", "window"])
  70.     except getopt.GetoptError:
  71.         # Unknown args were passed, we fallback to bahave as if
  72.         # no options were passed
  73.         opts = []
  74.         args = sys.argv[1:]
  75.  
  76.     for o, a in opts:
  77.         if o in ("-h", "--help"):
  78.             usage()
  79.         elif o in ("-d", "--debug"):
  80.             invest.DEBUGGING = True
  81.             invest.debug("Debugging enabled")
  82.             # these messages cannot be turned by invest.DEBUGGING at their originating location,
  83.             # because that variable was set here to be True
  84.             invest.debug("Data Dir: %s" % invest.SHARED_DATA_DIR)
  85.             invest.debug("Detected PROXY: %s" % invest.PROXY)
  86.         elif o in ("-w", "--window"):
  87.             standalone = True
  88.  
  89.     if standalone:
  90.         import gnome
  91.         gnome.init(invest.defs.PACKAGE, invest.defs.VERSION)
  92.         build_window()
  93.         gtk.main()
  94.     else:
  95.         gnomeapplet.bonobo_factory(
  96.             "OAFIID:Invest_Applet_Factory",
  97.             gnomeapplet.Applet.__gtype__,
  98.             invest.defs.PACKAGE,
  99.             invest.defs.VERSION,
  100.             applet_factory)
  101.